import { createRouter, createWebHashHistory } from 'vue-router'
import User from '../components/User'
import UserInfo from '../components/UserInfo'
const routes = [
  {
    path: '/',
    redirect: '/users' // 路由重定向到users
  },
  {
    path: '/users',
    name: 'User',
    component: User,
    meta: {
      title: '用户信息'
    }
  },
  {
    path: '/userInfo',
    name: 'UserInfo',
    component: UserInfo,
    meta: {
      title: '用户详情'
    }
  },
  {
    path: '/rights',
    name: 'Right',
    component: () =>
      import(/* webpackChunkName: "rights" */ '../components/Rights.vue'),
    meta: {
      title: '权限管理'
    }
  },
  {
    path: '/goods',
    name: 'Goods',
    component: () =>
      import(/* webpackChunkName: "rights" */ '../components/Goods.vue'),
    meta: {
      title: '商品管理'
    }
  },
  {
    path: '/orders',
    name: 'Orders',
    component: () => import(/* webpackChunkName: "rights" */ '../components/Orders.vue'),
    meta: {
      title: '订单管理'
    }
  },
  {
    path: '/settings',
    name: 'Settings',
    component: () =>
      import(/* webpackChunkName: "rights" */ '../components/Settings.vue'),
    meta: {
      title: '系统设置'
    }
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})
router.beforeEach((to, form, next) => {
  document.title = to.meta.title // 读取路由元信息，并修改网页标题
  next() // 跳转到指定页面
})
export default router
